'/
' MOTEP - Massive Online Text Environment Project
' --------------------------------------------------------------------------------
' Shared Code
' 
' NetUtil.bmx
' 
' (c) Anton Berlin. All Rights Reserved.
'/


'// -------------------------------------------------------------------------------------------------------------------
'// Description:
'//		Send a message to another peer.
'//		Packet channel example: You have chatmessages on channel 1, and movement on channel 2. This means they are
'//		ordered and sent seperately. The packets on channel 1 will not be ordered with the packets on channel 2.
'// 
'// Parameters:
'//		(TRKRakPeerInterface) p: The peer that sends the message.
'//		(string) mesg: The actual message to send.
'//		(int) packetChannel: Which channel to send the packet to.
'//		(TRKSystemAddress) targetAddr: The system address of the target (the guy we send this message to).
'// -------------------------------------------------------------------------------------------------------------------
function sendMessageToPeer(p:TRKRakPeerInterface, mesg:string, packetChannel:int, targetAddr:TRKSystemAddress)

	local message:byte ptr = mesg.ToCString()
	p.Send(message, mesg.length + 1, HIGH_PRIORITY, RELIABLE_ORDERED, 0, targetAddr, false)
	MemFree(message)

end function

'// -------------------------------------------------------------------------------------------------------------------
'// Description:
'//		Send a message to all connected peers.
'// 
'// Parameters:
'//		(TRKRakPeerInterface) p: The peer that sends the message.
'//		(string) mesg: The actual message to send.
'//		(int) packetChannel: Which channel to send the packet to.
'// -------------------------------------------------------------------------------------------------------------------
function sendMessageToAll(p:TRKRakPeerInterface, mesg:string, packetChannel:int)

	local message:byte ptr = mesg.ToCString()
	p.Send(message, mesg.length + 1, HIGH_PRIORITY, RELIABLE_ORDERED, 0, UNASSIGNED_SYSTEM_ADDRESS, true)
	MemFree(message)

end function

'// -------------------------------------------------------------------------------------------------------------------
'// Description:
'//		Send a message to all connected peers except one.
'// 
'// Parameters:
'//		(TRKRakPeerInterface) p: The peer that sends the message.
'//		(string) mesg: The actual message to send.
'//		(int) packetChannel: Which channel to send the packet to.
'//		(TRKSystemAddress) exception: The system address of the system we DON'T want to send the message to.
'// -------------------------------------------------------------------------------------------------------------------
function sendMessageToAllExceptOne(p:TRKRakPeerInterface, mesg:string, packetChannel:int, exception:TRKSystemAddress)

	local message:byte ptr = mesg.ToCString()
	p.Send(message, mesg.length + 1, HIGH_PRIORITY, RELIABLE_ORDERED, 0, exception, true)
	MemFree(message)

end function
